<?php
/*
	本插件：$this->model('news')->方法名();
	其他地方调用：model('jy_aiagent/news')->方法名();
*/
namespace jy_aiagent;
defined('BY_JYA') or exit('error');
class news extends \plugin{
	public function upnewstype(){
		$news_ntype=$this->demonews_ntype();
		foreach($news_ntype as $nv){
			$newstype=pdo_get('jy_aiagent_newstype',array('title'=>trim($nv['title']),'uniacid'=>$_SESSION['uniacid']));
			if(!$newstype){
				$data=array(
					'title'=>trim($nv['title']),
					'desc'=>trim($nv['desc']),
					'status'=>1,
				);
				$data['uniacid']=$_SESSION['uniacid'];
				$data['createtime']=TIMESTAMP;
				pdo_insert('jy_aiagent_newstype',$data);
				$pid=pdo_insertid();
			}else{
				$pid=$newstype['id'];
			}
			if($nv['list']){
				foreach($nv['list'] as $nv2){
					$newstype=pdo_get('jy_aiagent_newstype',array('title'=>trim($nv2['title']),'pid'=>$pid,'uniacid'=>$_SESSION['uniacid']));
					if(!$newstype){
						$data=array(
							'title'=>trim($nv2['title']),
							'desc'=>trim($nv2['desc']),
							'paixu'=>trim($nv2['paixu']),
							'pid'=>$pid,
							'aimy'=>trim($nv2['aimy']),
							'aito'=>trim($nv2['aito']),
							'aititle'=>trim($nv2['aititle']),
							'aineeds'=>ijson_encode($nv2['aineeds']),
							'status'=>1,
						);
						$data['uniacid']=$_SESSION['uniacid'];
						$data['createtime']=TIMESTAMP;
						pdo_insert('jy_aiagent_newstype',$data);
					}
				}
			}
		}
		return '';
	}
	public function news_ntype(){
		$list=pdo_getall('jy_aiagent_newstype',array('uniacid'=>$_SESSION['uniacid']),array('id','title','pid'));
		$newstype=array();
		foreach($list as $lv){
			if($lv['pid']){
				$ptitle=pdo_getcolumn('jy_aiagent_newstype',array('id'=>$lv['pid'],'uniacid'=>$_SESSION['uniacid']),'title');
				$newstype[$lv['id']]=$ptitle.'|'.$lv['title'];
			}else{
				$newstype[$lv['id']]=$lv['title'];
			}
		}
		return $newstype;
	}
	public function demonews_ntype(){
		$news_ntype=array(
			array('title'=>'语文辅导','aineeds'=>'回答简单，给出解题思路',
				'list'=>array(
					array('paixu'=>8,'title'=>'文字读写','aineeds'=>'回答简单，给出准确答案即可'),
					array('paixu'=>7,'title'=>'词语讲解','aineeds'=>'详细讲解词语意思'),
					array('paixu'=>7,'title'=>'成语故事','aineeds'=>'详细给出故事内容'),
					array('paixu'=>6,'title'=>'作文辅导','aineeds'=>'简单回答作文语句示例'),
				)
			),
			array('title'=>'数学辅导','aineeds'=>'回答简单，给出解题思路',
				'list'=>array(
					array('paixu'=>0,'title'=>'算术解答','aineeds'=>'回答简单，给出解题思路'),
					array('paixu'=>0,'title'=>'解题思路','aineeds'=>'回答简单，给出解题思路'),
					array('paixu'=>0,'title'=>'几何解答','aineeds'=>'回答简单，给出解题思路'),
					array('paixu'=>0,'title'=>'公式解答','aineeds'=>'回答简单，给出解题思路'),
				)
			),
			array('title'=>'英语辅导','aineeds'=>'回答简单，给出解题思路',
				'list'=>array(
					array('paixu'=>0,'title'=>'中文翻译','aineeds'=>'回答简单，给出准确答案即可'),
					array('paixu'=>0,'title'=>'单词翻译','aineeds'=>'回答简单，给出准确答案即可'),
					array('paixu'=>0,'title'=>'语句拼读','aineeds'=>'回答简单，给出准确答案即可'),
				)
			),
			array('title'=>'物理辅导','aineeds'=>'回答简单，给出解题思路',
				'list'=>array(
					array('paixu'=>0,'title'=>'物理原理','aineeds'=>'回答简单，给出解题思路'),
					array('paixu'=>0,'title'=>'解题思路','aineeds'=>'回答简单，给出解题思路'),
				)
			),
			array('title'=>'化学辅导','aineeds'=>'回答简单，给出解题思路',
				'list'=>array(
					array('paixu'=>0,'title'=>'化学原理','aineeds'=>'回答简单，给出解题思路'),
					array('paixu'=>0,'title'=>'解题思路','aineeds'=>'回答简单，给出解题思路'),
				)
			),
			array('title'=>'生物辅导','aineeds'=>'回答简单，给出解题思路',
				'list'=>array(
					array('paixu'=>0,'title'=>'生物原理','aineeds'=>'回答简单，给出解题思路'),
					array('paixu'=>0,'title'=>'解题思路','aineeds'=>'回答简单，给出解题思路'),
				)
			),
		);
		return $news_ntype;
	}
}
?>